package huzh.foundation.util;

/**
 *<p>title:ArgumentHolder</p>
 *<p>description:</p>
 * @since 2014-6-6
 * @author huzh
 * @version 1.0
 */
public class ArgumentHolder {
    /**cl*/
    @SuppressWarnings("unchecked")
    protected Class[] cl;
    /**args*/
    protected Object[] args;
    /**argc*/
    protected int argc;

    /**
     * 
     */
    public ArgumentHolder(){
        this.argc = 0;
        this.cl = new Class[0];
        this.args = new Object[0];
    }

    /**
     * @param argc
     */
    public ArgumentHolder(int argc) {
        this.argc = argc;
        this.cl = new Class[argc];
        this.args = new Object[argc];
    }

    /**
     * @return
     */
    @SuppressWarnings("unchecked")
    public Class[] getArgumentClasses() {
        return this.cl;
    }

    /**
     * @return
     */
    public Object[] getArguments() {
        return this.args;
    }

    /**
     * @param b
     * @return
     */
    public int setArgument(boolean b){
        return setArgument(this.argc, new Boolean(b), Boolean.TYPE);
    }

    /**
     * @param argnum
     * @param b
     * @return
     */
    public int setArgument(int argnum, boolean b){
        return setArgument(argnum, new Boolean(b), Boolean.TYPE);
    }

    public int setArgument(byte b){
        return setArgument(this.argc, new Byte(b), Byte.TYPE);
    }

    /**
     * @param argnum
     * @param b
     * @return
     */
    public int setArgument(int argnum, byte b){
        return setArgument(argnum, new Byte(b), Byte.TYPE);
    }

    /**
     * @param c
     * @return
     */
    public int setArgument(char c){
        return setArgument(this.argc, new Character(c), Character.TYPE);
    }

    /**
     * @param argnum
     * @param c
     * @return
     */
    public int setArgument(int argnum, char c) {
        return setArgument(argnum, new Character(c), Character.TYPE);
    }

    /**
     * @param i
     * @return
     */
    public int setArgument(int i){
        return setArgument(this.argc, new Integer(i), Integer.TYPE);
    }

    /**
     * @param argnum
     * @param i
     * @return
     */
    public int setArgument(int argnum, int i){
        return setArgument(argnum, new Integer(i), Integer.TYPE);
    }

    /**
     * @param s
     * @return
     */
    public int setArgument(short s){
        return setArgument(this.argc, new Short(s), Short.TYPE);
    }

    /**
     * @param argnum
     * @param s
     * @return
     */
    public int setArgument(int argnum, short s){
        return setArgument(argnum, new Short(s), Short.TYPE);
    }

    /**
     * @param l
     * @return
     */
    public int setArgument(long l){
        return setArgument(this.argc, new Long(l), Long.TYPE);
    }

    /**
     * @param argnum
     * @param l
     * @return
     */
    public int setArgument(int argnum, long l){
        return setArgument(argnum, new Long(l), Long.TYPE);
    }

    /**
     * @param f
     * @return
     */
    public int setArgument(float f){
        return setArgument(this.argc, new Float(f), Float.TYPE);
    }

    /**
     * @param argnum
     * @param f
     * @return
     */
    public int setArgument(int argnum, float f){
        return setArgument(argnum, new Float(f), Float.TYPE);
    }

    /**
     * @param d
     * @return
     */
    public int setArgument(double d){
        return setArgument(this.argc, new Double(d), Double.TYPE);
    }

    /**
     * @param argnum
     * @param d
     * @return
     */
    public int setArgument(int argnum, double d){
        return setArgument(argnum, new Double(d), Double.TYPE);
    }

    /**
     * @param obj
     * @return
     */
    public int setArgument(Object obj){
        return setArgument(this.argc, obj, obj.getClass());
    }

    /**
     * @param argnum
     * @param obj
     * @return
     */
    public int setArgument(int argnum, Object obj){
        return setArgument(argnum, obj, obj.getClass());
    }

    /**
     * @param argnum
     * @param obj
     * @param c
     * @return
     */
    @SuppressWarnings("unchecked")
    public int setArgument(int argnum, Object obj, Class c){
        if (argnum >= this.args.length) {
            this.argc = (argnum + 1);
            Class[] clExpanded = new Class[this.argc];
            Object[] argsExpanded = new Object[this.argc];
            System.arraycopy(this.cl, 0, clExpanded, 0, this.cl.length);
            System.arraycopy(this.args, 0, argsExpanded, 0, this.args.length);

            this.cl = clExpanded;
            this.args = argsExpanded;
        }
        this.args[argnum] = obj;
        this.cl[argnum] = c;
        return argnum;
    }
}
